package com.bootdo.updateApp.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.bootdo.common.controller.BaseController;
import com.bootdo.updateApp.domain.AppUpdate;
import com.bootdo.updateApp.service.AppUpdateService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 版本更新表
 * 
 * @author lujingqian
 * @email 2100272728@qq.com
 * @date 2019-11-20 09:16:19
 */
 
@Controller
@RequestMapping("/updateApp/appUpdate")
public class AppUpdateController extends BaseController{


	@Autowired
	private AppUpdateService appUpdateService;
	
	@ModelAttribute
	public AppUpdate get(@RequestParam(required=false) Integer id) {
		if (id != null){
			return appUpdateService.get(id);
		}else{
			return new AppUpdate();
		}
	}


	
	//insert into sys_menu(parent_id,name,url,perms,type)  values (149,'测试','/updateApp/appUpdate','updateApp:appUpdate:appUpdate',1)
	//insert into sys_menu(parent_id,name,url,perms,type)  values (160,'修改','','updateApp:appUpdate:edit',2)
	//type 0是分类菜单 1是小菜但 2是按钮
	@GetMapping()
	@RequiresPermissions("updateApp:appUpdate:appUpdate")	
	String AppUpdate(AppUpdate appUpdate,HttpServletRequest request,HttpServletResponse response){
	    return "updateApp/appUpdate/appUpdate";
	}
	
	@ResponseBody
	@PostMapping("/list")
	@RequiresPermissions("updateApp:appUpdate:appUpdate")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<AppUpdate> appUpdateList = appUpdateService.list(query);
		int total = appUpdateService.count(query);
		PageUtils pageUtils = new PageUtils(appUpdateList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("updateApp:appUpdate:edit")
	String add(AppUpdate appUpdate,HttpServletRequest request,HttpServletResponse response){
	    return "updateApp/appUpdate/appUpdateedit";
	}

	@PostMapping("/getById")
	@ResponseBody
	R getById(AppUpdate appUpdate) {
		return R.ok().put("i",appUpdate);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("updateApp:appUpdate:edit")
	public R save( AppUpdate appUpdate){
	
		if(appUpdateService.save(appUpdate)>0){
			return R.ok();
		}
		return R.error();
	}
	
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("updateApp:appUpdate:edit")
	public R remove( Integer id){
		if(appUpdateService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("updateApp:appUpdate:edit")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		appUpdateService.batchRemove(ids);
		return R.ok();
	}
	
}